Skip to content

Compare IntDot versions without splitting into slices - #67

Merged
andrew merged 2 commits into
git-pkgs:mainfrom
charlie-morrison:intdot-lockstep-compare
Nov 30, 2026
Merged

andrew merged 2 commits into
git-pkgs:mainfrom
charlie-morrison:intdot-lockstep-compare

Conversation

@charlie-morrison

@charlie-morrison charlie-morrison commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Refs #31, the IntDot item.

compareIntDot called strings.Split on both versions before comparing them (two allocations per call). It now walks both versions in lockstep, one dot-separated component at a time, and passes the same components to cmpNumStr. A side that runs out of components keeps yielding "", which is how a missing component compared before. intDotPrefix is unchanged.

go test -bench 'BenchmarkCompareWithScheme/IntDot' -benchmem, Go 1.26.7, linux/amd64, before and after run alternately (3 rounds of -count 3, so 9 runs each) on a slow, busy 2-core machine. Read the ratio, not the absolute numbers. The time gain on the uneven pair is within the noise here; the allocations are the steady part:

pair ns/op (median, min-max) B/op allocs/op
1.2.3 vs 1.2.4 main (0f1fb9f) 995 (698-1696) 96 2
this branch 461 (367-736) 0 0
1.2.3.4.5.6.7.8.9 vs 1.2.3.4.5.6.7.8 main 1768 (1575-2558) 272 2
this branch 1509 (933-2161) 0 0

Both rows are new in BenchmarkCompareWithScheme.

Coverage follows the ALPM/Conan/Gentoo rewrite:

  • intdot_reference_test.go is a mechanically renamed copy of the old intDotPrefix and compareIntDot.
  • TestCompareIntDotMatchesReference covers every ordered pair of the shared parity corpus plus IntDot forms: leading zeros, components past the 64-bit range, empty components from leading, repeated and trailing dots, long and uneven component counts, and the characters that end the numeric prefix (letters, -, ,, spaces, NUL, non-ASCII digits).
  • TestCompareIntDotMatchesReferenceOnFixtures covers every pair from the conformance fixtures.
  • FuzzCompareIntDotMatchesReference ran 60 s here (219k execs), with no difference.
  • IntDot joins TestEcosystemComparatorsDoNotAllocate with three pairs: equal length, uneven length, and a version with a suffix after the numeric prefix. All three fail on main with 2 allocations.

Mutations, one at a time, in a separate worktree: the loop stopping at the shorter side, no prefix trim on one side, a text comparison instead of cmpNumStr, one side reading the other side's index, the last component cut short, a past-the-end call returning a character, and a past-the-end index that never moves on. All 7 turn a test red. Two of them loop forever, so they fail on the 60 s test timeout.

go test ./... ok, golangci-lint run 0 issues, go vet ok, gofmt clean. Exported APIs and the scheme ordering are unchanged.

Summary by CodeRabbit

  • Performance
    • Dotted version comparisons now process components more efficiently, including versions with differing numbers of components and suffixes.
  • Tests
    • Expanded comparison checks across representative version strings and fixtures to verify results remain consistent.

compareIntDot split both versions with strings.Split before comparing,
which cost two allocations per call. It now walks both versions one
dot-separated component at a time, comparing the same components with
cmpNumStr, and a missing component still compares as "".

intdot_reference_test.go keeps the previous implementation as a reference
for parity tests over the shared corpus, IntDot edge cases and the
vers-spec fixtures, plus a fuzz target. IntDot joins
TestEcosystemComparatorsDoNotAllocate and BenchmarkCompareWithScheme.

Co-authored-by: Claude <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The IntDot comparator now compares dot-separated numeric components incrementally instead of using split slices. New tests compare its results with a retained reference implementation, and benchmark and allocation cases cover additional inputs.

Changes: IntDot comparison

Layer / File(s) Summary
Component comparison and parity checks
intdot_reference_test.go, schemes.go, intdot_parity_test.go
compareIntDot uses nextDotPart to compare components incrementally. Corpus, fixture, and fuzz tests compare its results with a split-based reference.
Benchmark and allocation checks
bench_test.go, ecosystem_extra_parity_test.go
Benchmark and allocation test cases cover equal and uneven component counts, including a suffixed version.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Refactor

Possibly related issues

  • git-pkgs/vers#31: The PR replaces strings.Split in compareIntDot with incremental component iteration, addressing the IntDot allocation objective.

Suggested reviewers: andrew

Merge Risk: Minimal · up to dc96b

This change reduces allocations when comparing dotted versions without changing the ordering results. Parity tests against the previous implementation cover the behavior, and no merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "Compare IntDot versions without splitting into slices" matches the main change. The raw summary and PR objectives both say compareIntDot now walks dot-separated components in lockstep with …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "Compare IntDot versions without splitting into slices" matches the main change. The raw summary and PR objectives both say compareIntDot now walks dot-separated components in lockstep with nextDotPart instead of using strings.Split. The title is specific, short, and free of noise.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: fe65696c-2b73-4c2b-bcc0-94a46110c67a
Commits

Reviewing files that changed from the base of the PR and between 0f1fb9f and dc96b18.

Files selected for processing: 5

  • bench_test.go
  • ecosystem_extra_parity_test.go
  • intdot_parity_test.go
  • intdot_reference_test.go
  • schemes.go

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@andrew
andrew merged commit d043dac into git-pkgs:main Nov 30, 2026
3 checks passed
@charlie-morrison
charlie-morrison deleted the intdot-lockstep-compare branch December 1, 2026 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants